<?php
// $range = 180 / pi() / 6372.797 * 0.5;
// echo $range;exit;0.0044953400769774
// echo $range / cos($lat * pi() / 180);0.0044953400769774
require_once "weixin_info.php";
require_once "config.php";
require_once __DIR__ . '/qiniu/autoload.php';

use Qiniu\Auth;//引入七牛云授权文件

// $fenlei = $mysql->query("select * from dyspw_member where shop_lat>31.314117659923 AND shop_lat<31.323108340077 AND shop_lng>120.67362992272 AND shop_lng<120.68415407728;");
// $fenlei_rows = $fenlei->fetch_all(MYSQLI_ASSOC);
// print_r($fenlei_rows);exit;
// require_once "jssdk.php";
// $jssdk = new JSSDK("wx16320d7479a5774c", "e111c965e8d4ba6a2ff1a99724f6d573");
// $signPackage = $jssdk->GetSignPackage();


//获取七牛云上传token

$accessKey = 'dZ4JiqyNgc6WgVEixLPUSzrEr3jUloZewEuV4gJI';
$secretKey = 'Intd7MmakuzmxeyY-OeEUPZHWFVaezLArY8Fid_9';

$auth = new Auth($accessKey, $secretKey);
// 要上传的空间
$bucket = 'education5p8';
// 生成上传 Token
$token = $auth->uploadToken($bucket);

$shop_id = !empty($_GET['shop_id']) ? $_GET['shop_id'] : '';
if (!empty($shop_id)) {
	$sql = "select * from dyspw_member where id = {$shop_id}";
	$loca_shop = mysqli_query($mysql, $sql);
	$shop_info = $loca_shop->fetch_all(MYSQLI_ASSOC);
}
// //视频类型
$fenlei = $mysql->query("select * from dyspw_weblinktype where parentid = 0 and checkinfo = true");
$fenlei_rows = $fenlei->fetch_all(MYSQLI_ASSOC);
// echo "select * from dyspw_shop_guide where guide_id = {$_SESSION['Member_info'][0]['id']}";exit;
$guide_sql = $mysql->query("select * from dyspw_shop_guide where guide_id = {$_SESSION['Member_info'][0]['id']}");
$guide = $guide_sql->fetch_all(MYSQLI_ASSOC);
if(!empty($guide)){
	$goods_sql = $mysql->query("select * from dyspw_goods where u_id = {$guide[0]['shop_id']}");
	$goods = $goods_sql->fetch_all(MYSQLI_ASSOC);
}
?>
<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
	<title>我拍吧</title>
	<script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>
	<script src="js/jquery.cookie.js" type="text/javascript"></script>
	<script src="js/layer/layer.js" type="text/javascript"></script>
	<script src="js/dsbridge.js" type="text/javascript"></script>
	<script src="js/app-login.js" type="text/javascript"></script>
	<!-- qiniu视频上传引用 -->

	<!--[if lte IE 8]>
	<script src="http://cdn.bootcss.com/jquery/1.9.0/jquery.min.js"></script>
	<![endif]-->
	<!--[if gt IE 8]>
	<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
	<![endif]-->
    <!-- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="js/qiniuUpload/css/index.css">
	<link rel="stylesheet" href="css/core.css?v=1.2">
	<!-- <script src="js/qiniuUpload/plupload/Moxie.swf" type="text/javascript"></script> -->
	<!-- <script src="js/qiniuUpload/qiniu/highlight.js" type="text/javascript"></script> -->

	<!-- <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
	<script src="https://cdn.bootcss.com/json3/3.3.2/json3.min.js"></script> -->
	<script src="js/bootstrap.min.js" type="text/javascript"></script>
	<script src="js/json3.min.js" type="text/javascript"></script>
	<script src="js/qiniuUpload/qiniu/plupload.full.min.js" type="text/javascript"></script>
	<script src="js/qiniuUpload/qiniu/qiniu.min.js" type="text/javascript"></script>
	<script src="js/qiniuUpload/qiniu/widget.js" type="text/javascript"></script>
	<script src="js/qiniuUpload/qiniu/common.js" type="text/javascript"></script>
	<script src="js/qiniuUpload/qiniu/ui.js" type="text/javascript"></script>
	<script src="js/qiniuUpload/qiniu/uploadWithOthers.js" type="text/javascript"></script>
	<script src="js/qiniuUpload/qiniu/uploadWithForm.js" type="text/javascript"></script>
	<script src="js/qiniuUpload/qiniu/uploadWithSDK.js" type="text/javascript"></script>
	<!-- <script src="js/qiniuUpload/qiniu/main.js" type="text/javascript"></script> -->
  <style>
		 /* 除步骤1外的UI默认都不可见 */
		.page-step-2 { display:none; }

		.video-input-box .btn-submit{
			width: 20rem;
		}

		#container{
			text-align: center;
		}

		.moxie-shim{
			display: none;
		}

		.progressContainer{
			-webkit-display: flex;
			-moz-display: flex;
			display: flex;
    		flex-flow: column;
		}

		.progressCancel{
			display: none!important;
		}

	</style>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<section>
	<!-- 视频预览 start -->
	<div class="video-info-box page-step-2">
		<div class="play"><img src="images/play.png" /><br />00:30</div>
		<video id="video_info" controls></video>
		<div class="" id="output"></div>
	</div>
	<!-- 视频预览 end -->
	<div class="video-input-box">
		<?php if (!empty($shop_id)) { ?>
			<div class="main" style="width:90%;">
				<div class="recharge-desc-box" style="border: 2px solid #fd7079;margin-bottom: 20px;padding: 10px;border-radius: 10px;margin-top: 20px;letter-spacing: 1px;">
					<p style="margin-bottom: 10px;">拍 <?php echo $shop_info[0]['username'] ?>店铺视频：		</p>
					<p style="text-indent: 10px;">分享至微信好友，微信群，或平台</p>
					<p style="text-indent: 10px;">用户购买后将返10%现金到您的账户</p>
				</div>
			</div>
		<?php
} ?>
		<div class="main" id="container">
			<div id="pickfiles"></div>
			<!-- 视频选择 start -->
			<div class="page-step-1" style="margin-bottom: 10%;height: 140px;">
				<span onclick="openLocalVideoActivity()" class="bendi" style="display: inline-block;width: 48%;text-align: center;padding: 20px 0px;position:relative;height: 100%;">
					<img src="./images/bendi.png" alt="">
					<p>本地视频</p>
					<!-- 调相册视频 -->
					<?php if ($_SERVER['HTTP_USER_AGENT'] == 'AndroidNative' || $_SERVER['HTTP_USER_AGENT'] == 'IosNative') { ?>
						<?php
						} else { ?>
						<input id="pickfiles" class="file-input" type="file" accept="video/mp4,video/mov" style="position: absolute;width:100%;height:100%;top: 0;opacity:0;" onchange="cameraDom(this)"/>
					<?php }?>
				</span>
				<span onclick="openRecordVideoActivity()" class="bendi" style="display: inline-block;width: 48%;text-align: center;padding: 20px 0px;position:relative;height: 100%;">
					<img src="./images/paise.png" alt="">
					<p>立即拍摄</p>
					<?php if ($_SERVER['HTTP_USER_AGENT'] == 'AndroidNative' || $_SERVER['HTTP_USER_AGENT'] == 'IosNative') { ?>
						<?php
						} else { ?>
						<input id="video_select_from_select_camera" type="file" accept="video/*" capture="camera" onchange="cameraDom(this)" style="position: absolute;width:100%;height:100%;top: 0;opacity:0;">
					<?php }?>
				</span>
			</div>
			<!-- 视频选择 end -->

			<!-- 调相册视频 -->
			<!-- <input id="video111" class="file-input" type="file" accept="video/mp4,video/mov" onchange="cameraDom(this)" style="display:none;"/> -->
			<!-- 调摄像头 -->
			<!-- <input id="video_select_from_select_camera" type="file" accept="video/*" capture="camera" onchange="cameraDom(this)" style="display:none;"> -->


			<div class="input-box"><input type="text" placeholder="请输入文字介绍" id="input"></div>

			<!-- <div class="input-box " id="jiequ" style="width:48%;float:right;"><button>自动截取封面</button><div class="" id="output"></div></div> -->
			<?php if (empty($shop_id)) { ?>
			<div class="cl">
				<?php if(empty($guide)){ ?>
					<!-- 判定当前用户是否为商户导购员 -->
					<div class="input-box" style="width:30%;margin-right:2%;display: inline-block;" id="tip ">
						<button id="allmap" >添加定位</button>
						<input type="hidden" name="lng" value="">
						<input type="hidden" name="lat" value="">
					</div>
					<div class="input-box" style="width:30%;margin-right:2%;display: inline-block;">
						<!-- <button>添加商户</button> -->
						<select class="shop_sel"  name="shop" style="width: 100%;line-height: 45px;display: inline;height: 38px;border: 0px;padding-left: 2px;background: #fff;">
							<option value="">选择商户</option>
						</select>
					</div>
				<?php }else{ ?>
					<div class="input-box" style="width:68%;margin-right:2%;display: inline-block;">
						<!-- <button>添加商户</button> -->
						<select class="guide"  name="guide" style="width: 100%;line-height: 45px;display: inline;height: 38px;border: 0px;padding-left: 2px;background: #fff;">
							<option value="0">选择商品</option>
							<?php foreach ($goods as $key => $val): ?>
								<option value="<?php echo $val['id'] ?>"><?php echo $val['title']; ?></option>
							<?php endforeach; ?>
						</select>
					</div>
				<?php } ?>

				<!-- <div class="input-box" style="width:24%; float:right; "><button>工具箱</button></div> -->
				<div class="input-box" style="width:30%;display: inline-block;">
					<select class="fl_sel" name="fl_sel" style="width: 100%;line-height: 45px;display: inline;height: 38px;border: 0px;padding-left: 2px;background: #fff; ">
						<option value="">选择分类</option>
						<?php foreach ($fenlei_rows as $key => $val) { ?>
							<option value="<?php echo $val['id']; ?>" ><?php echo $val['classname']; ?></option>
						<?php
				} ?>
					</select>
				</div>
				<div class="input-box" style="display:none;">
					<select class="goods_sel" name="goods_is" style="width: 100%;line-height: 45px;display: inline;height: 38px;border: 0px;padding-left: 2px;background: #fff; ">
						<option value="">选择商品</option>
					</select>
				</div>
				<!-- <div class="input-box facebtn" style="width:48%;" > -->
				<!-- <div class="input-desc face" style="    display: inline-block;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">上传封面图片(非必须)</div> -->
				<input type="hidden" name="back_img" value="">
			</div>
			<?php
	} ?>
			<form action="update.php" target="exec_target" method="POST" enctype="multipart/form-data" style="display:none;">
				<input type="hidden" name="FilePath" value="Goods/Thumb" />
				<input class="img_file" name="face" type="file" multiple=true value="" >
				<input type="submit" id="PicSubmit"/>
			</form>


			<iframe id="exec_target" name="exec_target" style="display:none"></iframe>

			<script type="text/javascript">
				$(".face").click(function(){
					$(".img_file").click();
				})
				// $(".yyzz_img").click(function(){
				// 	$(".img_file").click();
				// })
				$(".img_file").change(function(){
					$('#PicSubmit').click();
					$("#exec_target").load(function(){
						var data = $(window.frames['exec_target'].document.body).html();
						if(data != null){
							// $(".facebtn").find("img").attr("src",data );
							// $(".facebtn").find("img").show();
							$(".facebtn").find(".face").html(data);
							$(".facebtn").find("input").attr("value",data );
						}
					});
				})

			</script>

			<button class="btn-submit page-step-2" onclick="btn_submit_click()" >立即发布</button>
			</div>

			<div class="cl mainContainer">
				<!-- 进度显示 start -->
				<div class="nav-box" style="margin-top:30px;">
					<!-- <ul id="myTab" class="nav nav-tabs">
						<li role="presentation" class="active">
							<a href="#h5" name="h5" data-toggle="tab">
								七牛h5上传
							</a>
						</li>
						<li role="presentation">
							<a href="#expand" name="expand" data-toggle="tab">plupload插件上传</a>
						</li>
						<li role="presentation">
							<a href="#directForm" name="directForm" data-toggle="tab">form表单直传</a>
						</li>
					</ul> -->
					<div id="process" class="tab-content">
						<div class="tab-pane fade in active" id="h5">
							<div id="fsUploadProgress">

							</div>


							<!-- <table class="table table-striped table-hover text-left">
								<thead>
									<tr>
										<th class="col-md-4">Filename</th>
										<th class="col-md-2">Size</th>
										<th class="col-md-6">Detail</th>
									</tr>
								</thead>
								<tbody id="fsUploadProgress">

								</tbody>
							</table> -->
						</div>
						<!-- <div class="tab-pane fade" id="expand">
							<table class="table table-striped table-hover text-left" style="margin-top:30px">
								<thead>
									<tr>
										<th class="col-md-4">Filename</th>
										<th class="col-md-2">Size</th>
										<th class="col-md-6">Detail</th>
									</tr>
								</thead>
								<tbody id="fsUploadProgress2">

								</tbody>
							</table>
						</div> -->
						<!-- <div class="tab-pane fade" id="directForm">
							<form id="uploadForm" class="picForm" method="post" action="" enctype="multipart/form-data" target="ifram">
								<button style="color:#fff;background-color:#00b7ee;position:relative;top:30px;font-weight:100;height:30px;font-size:14px;width:80px;">选择文件</button>
								<input style="width:80px;height:30px;opacity:0;cursor:pointer" type="file" name="file" id="select3" />
								<input name="token" style="display:none">
								<input name="key" style="display:none" />
								<input name="url" style="display:none" />
							</form>
							<table class="table table-striped table-hover text-left" style="margin-top:30px">
								<thead>
									<tr>
										<th class="col-md-4">Filename</th>
										<th class="col-md-2">Size</th>
										<th class="col-md-6">Detail</th>
									</tr>
								</thead>
								<tbody id="fsUploadProgress3">

								</tbody>
							</table>
						</div> -->
					</div>
				</div>
				<!-- end -->
			</div>

			<!-- <form id="video_select_from" style="display:none">
				<input id="video_select_from_select_file" type="file" accept="video/mp4,video/mov" onchange="on_video_select('file')">
				<input id="video_select_from_select_camera" type="file" accept="video/*" capture="camera" onchange="on_video_select('camera')">
			</form> -->
		</div>
	</div>

	<div class="zhezhao" style="width: 100%;height: 100%;position: fixed;top: 0;left: 0;background: rgba(0,0,0,0.3);z-index: 99; display:none;">
		<img src="images/baishe.gif" alt="" style="width: 100px;position: relative;top: calc(50% - 50px);left: calc(50% - 50px);">
	</div>
</section>
<script type="text/javascript" src="//webapi.amap.com/maps?v=1.4.1&key=d021bae86db1d54dddc4071a5123749c"></script>
<script type="text/javascript">

const _token = '<?php echo $token ?>';
const _accessKey = '<?php echo $accessKey ?>';
const _secretKey = '<?php echo $secretKey ?>';
const _bucket = '<?php echo $bucket ?>';

let linkurl = '';
let uploader;
let _obj;

let file = null; // 选中的文件对象

function cameraDom(obj){
	if(file != null){
		uploader.removeFile(file);
	}

	file = $(obj).get(0).files[0];
	console.log(file);
	uploader.addFile(file);
	uploader.init(file);
}

 window.getCamera = function(str){
	if (str) {
		linkurl = str;
		on_video_select();
	}
}

function openRecordVideoActivity() {
	var res = dsBridge.call("openRecordVideoActivity","openRecordVideoActivity");
	// javascript:android.openRecordVideoActivity();
}

function openLocalVideoActivity() {
	// javascript:android.openLocalVideoActivity();
	var res = dsBridge.call("openLocalVideoActivity","openLocalVideoActivity");
	// alert('测试APP定位功----openLocalVideoActivity：' + res)
}

function checkAndroid() {
	var ua = window.navigator.userAgent;
	  //通过正则表达式匹配ua中是否含有MicroMessenger字符串
	  console.log('uauauauaua', ua);
  	if(ua == 'AndroidNative'){
		$('#video_select_from_select_camera').css("display", "none");
		$('.file-input').css("display", "none");
  	}
}
checkAndroid();


// ----------------------------------------------------------------------------
// 视频选择
function on_video_select() {
// 	 file = $(`#video_select_from_select_${opt}`).get(0).files[0]
//   const ext = file.name.split('.').pop().toLowerCase()
// 	if (['mp4', 'mov'].indexOf(ext) < 0) {
// 		alert(`![${file.name}], 只支持 mp4, mov 文件`)
// 		return;
// 	}
// 	if (file.size > (1024 * 1024 * 200)) {
// 		let size = (file.size / 1024 / 1024).toFixed(2)
// 		alert(`size:[${size}M],视频文件最多支持200M以内`)
// 		return;
// 	}
	// file.oss = {
	// 	ext,
	// 	local: window.URL.createObjectURL(file) // 将选择的视频文件转成可访问的本地url,作预览用
	// }

	// $('#video_info').attr('src', file.oss.local)

	$('#video_info').attr('src', 'https://jianshen.fyh5p8.com/' + linkurl)
	// $('#video_select_from').get(0).reset();
	$('.page-step-1').hide();
	$('.page-step-2').show();
}

// ----------------------------------------------------------------------------
// 提交
function btn_submit_click() {
	if($("#input").val() == '') {
		layer.open({content:"请输入文字介绍",skin:'msg',time:3});
		return false;
	}

	if(linkurl == ''){
		layer.open({content:"未选择视频",skin:'msg',time:3});
		return false;
	}

	<?php if (empty($shop_id)) { ?>
		if($(".fl_sel").val() == '') {
			layer.open({content:"请选择上传分类",skin:'msg',time:3});
			return false;
		}
	<?php
} ?>

	do_submit();
  //console.log('正在上传文件, 请等待'); // 此处可加一个loading 特效增加用户体验
  // 上传文件
	// #上传逻辑直接拷贝自index.php  本人未经过测试
	// let formFile={
    //     insert: 1,
    //     siteid: 1,
    //     classid: $(".fl_sel").val(),//视频分类id
    //     u_id: "<?php echo $_SESSION['Member_info'][0]['id'] ?>", //用户id
    //     avatar: 'uploads/image/20200402/1585816181.jpg', //用户头像
    //     webname: "<?php echo $_SESSION['Member_info'][0]['username'] ?>", //用户昵称
    //     webnote: $('#input').val(), //视频标题
    //     picurl: $("input[name='back_img']").val() == '' ? '' : $("input[name='back_img']").val(), //封面图片src地址 可为空
    //     linkurl: 'https://jianshen.fyh5p8.com/' + linkurl
	// }

	// console.log('最终提交:',formFile)

	// $.ajax({
	// 		url:'fileup.php',
	// 		data:formFile,
	// 		dataType:'json',
	// 		type:'post',
	// 		// processData: false,
	// 		// contentType: false,
	// 		success:function (data) {
	// 			// console.log('上传视频到服务器的返回：',data);
	// 			$(".zhezhao").hide();
	// 			if (data.code==200) {
	// 				layer.open({content: '发布成功！',skin:'msg',time:3});
	// 				do_submit(linkurl);
	// 			} else {
	// 				layer.open({content: data.msg,skin:'msg',time:3});
	// 			}
	// 		},
	// 		error: function() {
	// 			$(".zhezhao").hide();
	// 			layer.open({content: '上传错误',skin:'msg',time:3});
	// 		}
	// })
}

// 正式提交表单
// #提交逻辑直接拷贝自原上传按钮事件  本人未经过测试
function do_submit() {
	var formdata = new FormData();
	var u_id = "<?php echo $_SESSION['Member_info'][0]['id'] ?>";
	var u_img = "<?php echo $_SESSION['Member_info'][0]['avatar'] ?>";
	var u_name = "<?php echo $_SESSION['Member_info'][0]['username'] ?>";
	var openid = "<?php echo $_SESSION['Member_info'][0]['openid'] ?>";
	var is_vip = "<?php echo $_SESSION['Member_info'][0]['is_vip'] ?>";

	var input  = $('#input').val();

	<?php if (empty($shop_id)) { ?>
		var back_img = $("input[name='back_img']").val();
		var lat = $("input[name='lat']").val();
		var lng = $("input[name='lng']").val();
		var goods_sel = $(".goods_sel").val();
		var fl_sel = $(".fl_sel").val();
		var shop_sel = $(".shop_sel").val();
	<?php } else { ?>
			var back_img = '';
			var lat = '';
			var lng = '';
			var goods_sel = '';
			var fl_sel = '';
			var shop_sel = "<?php echo $shop_id; ?>";
		<?php
	} ?>
	<?php if(!empty($guide)){ ?>
		goods_sel = $(".guide").val();
	<?php } ?>
	formdata.append('picurl',back_img);
	formdata.append('linkurl', 'https://jianshen.fyh5p8.com/' + linkurl);
	formdata.append('u_id', u_id);
	formdata.append('avatar', u_img);
	formdata.append('webname', u_name);
	formdata.append('webnote', input);
	formdata.append('lat', lat);
	formdata.append('lng', lng);
	formdata.append('classid', fl_sel);
	formdata.append('shop_id', shop_sel);
	formdata.append('goods_id', goods_sel);
	formdata.append('is_vip', is_vip);
		// console.log(u_name)


	// console.log('formdata:',formdata)

	$.ajax({
			url:'weblinkInfoUp.php',
			data:formdata,
			dataType:'JSON',
			type:'post',
			processData: false,
			contentType: false,
			success:function (data) {
				// console.log(data,222222222)
				if(data.code=='y'){
					layer.open({content:data.info,skin:'msg',time:2});
					setTimeout(() => {
						location.href="index.php";
					}, 2000);
				}else{
					layer.open({content:data.info,skin:'msg',time:3});
				}

			}
	})
}

// ----------------------------------------------------------------------------

$(function(){
 uploader = Qiniu.uploader({
        disable_statistics_report: false,
        runtimes: 'html5,flash,html4', // 上传模式，依次退化
        browse_button: 'pickfiles', // 上传选择文件的点选按钮，必需
        container: 'container', // 上传区域DOM ID，默认是browser_button的父元素
        drop_element: 'container', //拖曳上传区域元素的ID，拖曳文件或文件夹后可触发上传
        max_file_size: '1000mb', // 最大文件体积限制
        flash_swf_url: '/js/qiniuUpload/plupload/Moxie.swf', // 引入flash，相对路径
        dragdrop: true, // 关闭可拖曳上传
        chunk_size: '4mb', // 分块上传时，每块的体积
        // multi_selection: !(moxie.core.utils.Env.OS.toLowerCase() === "ios"),
        multi_selection: false,
        uptoken: _token,
        // uptoken_url: '/app/informationTime/gettoken', //Ajax请求upToken的Url，**强烈建议设置**（服务端提供）
        // uptoken_func: function(){
        //     var ajax = new XMLHttpRequest();
        //     ajax.open('GET', $('#uptoken_url').val(), false);
        //     ajax.setRequestHeader("If-Modified-Since", "0");
        //     ajax.send();
        //     if (ajax.status === 200) {
        //         var res = JSON.parse(ajax.responseText);
        //         console.log('custom uptoken_func:' + res.uptoken);
        //         return res.uptoken;
        //     } else {
        //         console.log('custom uptoken_func err');
        //         return '';
        //     }
		// },
		// filters: {
		// 	mime_types: [
		// 		{
		// 			title: "Video files",
		// 			extensions: "flv,mpg,mpeg,avi,wmv,mov,asf,rm,rmvb,mkv,m4v,mp4"
		// 		}
		// 	],
		// 	prevent_duplicates: true, //不允许选取重复文件
		// },
        domain: _bucket, // bucket域名，下载资源时用到，必需
        get_new_uptoken: false, // 设置上传文件的时候是否每次都重新获取新的uptoken
        //downtoken_url: '/downtoken',
        // unique_names: true,
        // save_key: true,
        // x_vars: {
        //     'id': '1234',
        //     'time': function(up, file) {
        //         var time = (new Date()).getTime();
        //         // do something with 'time'
        //         return time;
        //     },
        // },
        auto_start: true, // 选择文件后自动上传，若关闭需要自己绑定事件触发上传
        log_level: 5,
        init: {
            'BeforeChunkUpload': function(up, file) {
                // console.log("before chunk upload:", file.name);
				//判断文件格式
				var index1 = file.name.lastIndexOf(".");
                var index2 = file.name.length;
                var newfile = file.name.substring(index1 + 1, index2);
				// console.log(newfile,'newfile')
				if (newfile == "flv" ||
				newfile == "mpg" ||
				newfile == "mpeg" ||
				newfile == "avi" ||
				newfile == "wmv" ||
				newfile == "mov" ||
				newfile == "asf" ||
				newfile == "rm" ||
				newfile == "rmvb" ||
				newfile == "mkv" ||
				newfile == "m4v" ||
				newfile == "mp4"
				) {
					return;
				}else{
					layer.open({ content: '视频格式不正确！', skin: 'msg', time: 3 });
					uploader.removeFile(file);
					$(".zhezhao").hide(); //关闭loading
					return false;
				}

            },
            'FilesAdded': function(up, files) {
                // 文件添加进队列后，处理相关的事情
                $('table').show();
                $(".zhezhao").show(); //开启loading
                plupload.each(files, function(file) {
                    var progress = new FileProgress(file,
                        'fsUploadProgress');
                    progress.setStatus("等待...");
                    progress.bindUploadCancel(up);
                });
            },
            'BeforeUpload': function(up, file) {



                // 每个文件上传前，处理相关的事情
                // console.log("this is a beforeupload function from init");
                var progress = new FileProgress(file, 'fsUploadProgress');
                var chunk_size = plupload.parseSize(this.getOption(
                    'chunk_size'));
                if (up.runtime === 'html5' && chunk_size) {
                    progress.setChunkProgess(chunk_size);
                }
            },
            'UploadProgress': function(up, file) {
                // 每个文件上传时，处理相关的事情
                var progress = new FileProgress(file, 'fsUploadProgress');
                var chunk_size = plupload.parseSize(this.getOption(
                    'chunk_size'));
                progress.setProgress(file.percent + "%", file.speed,
                    chunk_size);
            },
            'UploadComplete': function() {
                //队列文件处理完毕后，处理相关的事情
                //得到最后的文件名 存储传给服务端
                // $('#success').show();
                // $('#videoRevoke').css("display", "block");
                /*只能上传一个视频*/
                // $("#container").css("display", "none");
            },
            'FileUploaded': function(up, file, info) {
                // 每个文件上传成功后，处理相关的事情
                var progress = new FileProgress(file, 'fsUploadProgress');
                // console.log("info111111111111111111:", info);
                //console.log("response:", info.response);

                progress.setComplete(up, info.response);
				if(info.response != ''){
					_obj = JSON.parse(info.response);
                	linkurl = _obj.key;
				}



				$(".zhezhao").hide(); //关闭loading
				layer.open({ content: '视频上传完成！', skin: 'msg', time: 3 });
				on_video_select() //本地预览



            },
            'Error': function(up, err, errTip) {
                    //上传出错时,处理相关的事情
                    // $('table').show();
                    var progress = new FileProgress(err.file, 'fsUploadProgress');
                    progress.setError();
                    progress.setStatus(errTip);
                }
                // ,
                // 'Key': function(up, file) {
                // 若想在前端对每个文件的key进行个性化处理，可以配置该函数
                // 该配置必须要在 unique_names: false , save_key: false 时才生效
                //     var key = "";
                //     // do something with key
                //     return key
                // }
        }
    });
    //uploader.init();
    uploader.bind('BeforeUpload', function() {
        console.log("开始上传file");
		$('.mainContainer').show();
    });
    uploader.bind('FileUploaded', function(e) {
		console.log('上传结束！');
		$('.mainContainer').hide();
    });
    $('#container').on(
        'dragenter',
        function(e) {
            e.preventDefault();
            $('#container').addClass('draging');
            e.stopPropagation();
        }
    ).on('drop', function(e) {
        e.preventDefault();
        $('#container').removeClass('draging');
        e.stopPropagation();
    }).on('dragleave', function(e) {
        e.preventDefault();
        $('#container').removeClass('draging');
        e.stopPropagation();
    }).on('dragover', function(e) {
        e.preventDefault();
        $('#container').addClass('draging');
        e.stopPropagation();
    });



    $('#show_code').on('click', function() {
        $('#myModal-code').modal();
        $('pre code').each(function(i, e) {
            hljs.highlightBlock(e);
        });
    });


    $('body').on('click', 'table button.btn', function() {
        $(this).parents('tr').next().toggle();
    });


    var getRotate = function(url) {
        if (!url) {
            return 0;
        }
        var arr = url.split('/');
        for (var i = 0, len = arr.length; i < len; i++) {
            if (arr[i] === 'rotate') {
                return parseInt(arr[i + 1], 10);
            }
        }
        return 0;
    };

    $('#myModal-img .modal-body-footer').find('a').on('click', function() {
        var img = $('#myModal-img').find('.modal-body img');
        var key = img.data('key');
        var oldUrl = img.attr('src');
        var originHeight = parseInt(img.data('h'), 10);
        var fopArr = [];
        var rotate = getRotate(oldUrl);
        if (!$(this).hasClass('no-disable-click')) {
            $(this).addClass('disabled').siblings().removeClass('disabled');
            if ($(this).data('imagemogr') !== 'no-rotate') {
                fopArr.push({
                    'fop': 'imageMogr2',
                    'auto-orient': true,
                    'strip': true,
                    'rotate': rotate,
                    'format': 'png'
                });
            }
        } else {
            $(this).siblings().removeClass('disabled');
            var imageMogr = $(this).data('imagemogr');
            if (imageMogr === 'left') {
                rotate = rotate - 90 < 0 ? rotate + 270 : rotate - 90;
            } else if (imageMogr === 'right') {
                rotate = rotate + 90 > 360 ? rotate - 270 : rotate + 90;
            }
            fopArr.push({
                'fop': 'imageMogr2',
                'auto-orient': true,
                'strip': true,
                'rotate': rotate,
                'format': 'png'
            });
        }

        $('#myModal-img .modal-body-footer').find('a.disabled').each(
            function() {

                var watermark = $(this).data('watermark');
                var imageView = $(this).data('imageview');
                var imageMogr = $(this).data('imagemogr');

                if (watermark) {
                    fopArr.push({
                        fop: 'watermark',
                        mode: 1,
                        image: 'http://www.b1.qiniudn.com/images/logo-2.png',
                        dissolve: 100,
                        gravity: watermark,
                        dx: 100,
                        dy: 100
                    });
                }

                if (imageView) {
                    var height;
                    switch (imageView) {
                        case 'large':
                            height = originHeight;
                            break;
                        case 'middle':
                            height = originHeight * 0.5;
                            break;
                        case 'small':
                            height = originHeight * 0.1;
                            break;
                        default:
                            height = originHeight;
                            break;
                    }
                    fopArr.push({
                        fop: 'imageView2',
                        mode: 3,
                        h: parseInt(height, 10),
                        q: 100,
                        format: 'png'
                    });
                }

                if (imageMogr === 'no-rotate') {
                    fopArr.push({
                        'fop': 'imageMogr2',
                        'auto-orient': true,
                        'strip': true,
                        'rotate': 0,
                        'format': 'png'
                    });
                }
            });

        var newUrl = Qiniu.pipeline(fopArr, key);

        var newImg = new Image();
        img.attr('src', '/images/loading.gif');
        newImg.onload = function() {
            img.attr('src', newUrl);
            img.parent('a').attr('href', newUrl);
        };
        newImg.src = newUrl;
        return false;
    });
















	$("#jiequ").click(function(){
		var video = document.getElementById("video_info");
		jiequ(video);
	});
	function jiequ(video){
		var canvas = document.createElement("canvas");
		canvas.width = video.videoWidth * 0.3;
		canvas.height = video.videoHeight * 0.3;
		canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
		var img = document.createElement("img");
		img.src = canvas.toDataURL("image/png");
		$("#output").append(img);
	}

	$("#allmap").click(function(){

		var map, geolocation;
		map = new AMap.Map('allmap');
		map.plugin('AMap.Geolocation', function() {
			geolocation = new AMap.Geolocation({
				enableHighAccuracy: true //是否使用高精度定位，默认:true
			});
			geolocation.getCurrentPosition();
			AMap.event.addListener(geolocation, 'complete', function(point){
				var lnglatXY = [point.position.lng, point.position.lat]; //已知点坐标
				map.plugin('AMap.Geocoder', function() {
					var geocoder = new AMap.Geocoder();
					geocoder.getAddress(lnglatXY, function(status, result) {
						if (status === 'complete' && result.info === 'OK') {
							var address = result.regeocode.formattedAddress;
							var obj = result.regeocode.addressComponent;
							address = address.replace(obj.province, '');
							address = address.replace(obj.district, '');
							address = address.replace(obj.city, '');
							var lng = point.position.lng;
							var lat = point.position.lat;
							console.log(address);
							$("input[name='lng']").attr('value', point.position.lng);
							$("input[name='lat']").attr('value', point.position.lat);
							console.log(point.position.lng,point.position.lat);
							$.ajax({
					            url:'baishe_ajax.php',
					            data:{'lng':lng, 'lat':lat},
					            dataType:'JSON',
					            type:'post',
					            // processData: false,
								success:function (ret) {
									if(ret.status == 'y'){
										var option = '';
									  $.each(ret.data, function(k,v){
											option += "<option value="+this.id+">"+this.username+"</option>";
										});
										$(".shop_sel").empty()
										$(".shop_sel").append(option);
									}else if (data.status == 'n') {
										layer.open({content:data.info,skin:'msg',time:3});
									}
								}
							})
						}
					});
				});
			});
		});
	})

	//商品选择改变时出发获取商品
	$(".shop_sel").bind("change", function(){
		var id = $(this).val();
			$(".goods_sel").empty()
			$.ajax({
				url:'Get_GoodsList.php',
				data:{'id':id},
				dataType:'JSON',
				type:'post',
				success:function (ret) {
					if(ret.status == 'y'){
						var option = '';
					  $.each(ret.data, function(){
							console.log(this.id, this.title);
							option += "<option value="+this.id+">"+this.title+"</option>";
						});
						$(".goods_sel").parent().show();
						$(".goods_sel").append(option);
					}else if (data.status == 'n') {
						layer.open({content:data.info,skin:'msg',time:3});
					}
				}
			})
	})


//上传时做角色限定  游客上传时定位于选择商品不可见



    $(".play").click(function(){
		// $(".video-img").hide();
		$('video').trigger('play');
		// var video = document.querySelector('#video_info');
		// video.display = 'block';
    	// video.play();
		$(this).hide();
	});
});

</script>
</body>
</html>
